function HebcaClient() {
	this.clientCtrl = null
}
function HebcaP11XObject(a) {
	var b = null;
	if (void 0 !== window.ActiveXObject)
		try {
			b = new ActiveXObject("HebcaP11X.CertMgr")
		} catch (c) {
			throw Error("没有安装客户端软件或IE阻止其运行.")
		}
	else {
		var d = "application/hebca-np11x-plugin";
		if (!(navigator.mimeTypes && navigator.mimeTypes[d] && navigator.mimeTypes[d].enabledPlugin))
			throw Error("请检查是否安装河北CA数字证书多浏览器客户端或被浏览器禁用!\r\n安装或启用后重新打开浏览器再试！");
		if (null != GlobalHebcaP11XObj)
			return GlobalHebcaP11XObj;
		var e = document.createElement("embed");
		e.setAttribute("id", "npP11Xplugin"), e.setAttribute("type", d), e
				.setAttribute("width", 0), e.setAttribute("height", 0), document.body
				.appendChild(e), b = document.getElementById("npP11Xplugin");
		try {
			b.CheckBlockedByBrowser()
		} catch (c) {
			throw Error("插件未安装或被浏览器阻止.")
		}
		var f = b.CheckP11XInstalled();
		if (0 == f)
			throw Error("数字证书助手未安装.")
	}
	return GlobalHebcaP11XObj = b, b
}
function HebcaP11XLastError() {
	var a;
	if (1 == arguments.length)
		a = arguments[0];
	else {
		if (2 != arguments.length)
			return "HebcaP11XLastError参数不正确";
		a = arguments[1]
	}
	return void 0 !== window.ActiveXObject
			? a.message
			: "NP11X_EXCEPTION_MSG" == a.message || "NP11X_EXCEPTION_MSG" == a
					? GlobalHebcaP11XObj.GetLastErr()
					: a.message
}
function getCertInfo() {
	var a = document.getElementById("taxId").value;
	markCertObj.TaxID = a, markCertObj.pluginStatus
			&& markCertObj.GetCertInfoEX()
}
function testEncryptData() {
	var a = document.getElementById("taxId").value, b = document
			.getElementById("passwd").value, c = document
			.getElementById("stringstring").value;
	markCertObj.TaxID = a;
	document.getElementById("encData").value, document
			.getElementById("signData").value;
	markCertObj.pluginStatus && markCertObj.EncryptData(c, b)
}
function testGetVersion() {
	markCertObj.pluginStatus && markCertObj.GetVersion()
}
function testCheckUsbKey() {
	markCertObj.pluginStatus
			&& self.setInterval("markCertObj.CheckUsbKey();", 2e3)
}
function getOSAndBrowser() {
	var a = navigator.platform, b = navigator.userAgent, c = "", d = "", e = !1, f = !1;
	return a.indexOf("Win") > -1
			&& (b.indexOf("Windows NT 5.0") > -1 ? e = !0 : b
					.indexOf("Windows NT 5.1") > -1 ? e = !0 : b
					.indexOf("Windows NT 5.2") > -1 ? e = !0 : b
					.indexOf("Windows NT 6.0") > -1 ? e = !0 : b
					.indexOf("Windows NT 6.1") > -1
					|| b.indexOf("Windows 7") > -1 ? e = !0 : b
					.indexOf("Windows 8") > -1
					|| b.indexOf("Windows NT 6.2") > -1
					|| b.indexOf("Windows NT 6.3") > -1 ? e = !0 : b
					.indexOf("Windows NT 10.0") > -1
					&& (e = !0)), c += "/", /[Ff]irefox(\/\d+\.\d+)/.test(b)
			? f = !0
			: /MSIE \d+\.\d+/.test(b)
					? (d = /MS(IE) (\d+\.\d+)/.exec(b), f = !0)
					: /[Cc]hrome\/\d+/.test(b)
							? f = !0
							: (window.ActiveXObject || "ActiveXObject" in window)
									&& (f = !0), e && f
			? !0
			: "当前配置可能会影响空间使用，推荐使用XP/WIN7/WIN8 + IE/Chrome"
}
function GetList(strListID) {
	for (var objListID = eval(strListID), strUserList = XTXAPP
			.SOF_GetUserList();;) {
		var i = strUserList.indexOf("&&&");
		if (0 >= i)
			break;
		var strOneUser = strUserList.substring(0, i), strName = strOneUser
				.substring(0, strOneUser.indexOf("||")), strUniqueID = strOneUser
				.substring(strOneUser.indexOf("||") + 2, strOneUser.length), objItem = new Option(
				strName, strUniqueID);
		objListID.options.add(objItem);
		var len = strUserList.length;
		strUserList = strUserList.substring(i + 3, len)
	}
	var objListID = null
}
function RemoveUserList(strListID) {
	var objListID = eval(strListID), i, n = objListID.length;
	for (i = 0; n > i; i++)
		objListID.remove(0)
}
function ChangeUserList(a) {
	RemoveUserList(a), GetList(a)
}
function GetUserList() {
	return XTXAPP.SOF_GetUserList()
}
function SetEncryptMethod(a) {
	return XTXAPP.SOF_SetEncryptMethod(a)
}
function SetSignMethod(a) {
	return XTXAPP.SOF_SetSignMethod(a)
}
function GetCertBasicinfo(a, b) {
	return XTXAPP.SOF_GetCertInfo(a, b)
}
function GetExtCertInfoByOID(a, b) {
	return XTXAPP.SOF_GetCertInfoByOid(a, b)
}
function GetExchCert(a) {
	var b = XTXAPP.SOF_ExportExChangeUserCert(a);
	return b
}
function GetSignCert(a) {
	var b = XTXAPP.SOF_ExportUserCert(a);
	return b
}
function SignedDataXML(a, b) {
	return XTXAPP.SOF_SignDataXML(b, a)
}
function SignedData(a, b) {
	return null != a ? XTXAPP.SOF_SignData(a, b) : ""
}
function VerifySignedData(a, b, c) {
	return XTXAPP.SOF_VerifySignedData(a, b, c)
}
function EncryptData(a, b) {
	var c = XTXAPP.SOF_SymEncryptData(a, b);
	return c
}
function DecryptData(a, b) {
	var c = XTXAPP.SOF_SymDecryptData(a, b);
	return c
}
function GenerateRandom(a) {
	return XTXAPP.SOF_GenRandom(a)
}
function SignFile(a, b) {
	return XTXAPP.SOF_SignFile(b, a)
}
function VerifySignFile(a, b, c) {
	return XTXAPP.SOF_VerifySignedFile(b, a, c)
}
function ChangeUserPassword(a, b, c) {
	return XTXAPP.SOF_ChangePassWd(a, b, c)
}
function SignedDataXML(a, b) {
	return XTXAPP.SOF_SignDataXML(b, a)
}
function VerifySignXML(a) {
	return XTXAPP.SOF_VerifySignedDataXML(a)
}
function SignByP7(a, b) {
	return XTXAPP.SOF_SignMessage(0, a, b)
}
function VerifyDatabyP7(a) {
	return XTXAPP.SOF_VerifySignedMessage(a, "")
}
function EncodeP7Enveloped(a, b) {
	return XTXAPP.SOF_EncryptDataEx(a, b)
}
function DecodeP7Enveloped(a, b) {
	return XTXAPP.SOF_DecryptData(a, b)
}
function Base64Encode(a) {
	return XTXAPP.SOF_Base64Encode(a)
}
function Base64Decode(a) {
	return XTXAPP.SOF_Base64Decode(a)
}
function SymEncryptFile(a, b, c) {
	return XTXAPP.SOF_SymEncryptFile(a, b, c)
}
function SymDecryptFile(a, b, c) {
	return XTXAPP.SOF_SymDecryptFile(a, b, c)
}
function PubKeyEncrypt(a, b) {
	return XTXAPP.SOF_PubKeyEncrypt(a, b)
}
function PriKeyDecrypt(a, b) {
	return XTXAPP.SOF_PriKeyDecrypt(a, b)
}
function HashFile(a, b) {
	return XTXAPP.SOF_HashFile(a, b)
}
function GetLastError() {
	return XTXAPP.SOF_GetLastError()
}
function GetLastErrorMsg() {
	var a = XTXAPP.SOF_GetLastError(), b = XTXAPP.SOF_GetLastErrMsg();
	return "错误码[" + a + "] 错误描述[" + b + "]"
}
function CheckValid(a) {
	var b = XTXAPP.SOF_GetCertInfo(a, CERT_NOT_BEFORE), c = b.substring(0, 4)
			+ "/" + b.substring(4, 6) + "/" + b.substring(6, 8), d = (new Date)
			.Format("yyyy/MM/dd"), e = (Date.parse(c) - Date.parse(d)) / 864e5;
	if (e > 0)
		return alert("您的证书尚未生效!距离生效日期还剩" + e + "天!"), !1;
	var f = XTXAPP.SOF_GetCertInfo(a, CERT_NOT_AFTER), g = f.substring(0, 4)
			+ "/" + f.substring(4, 6) + "/" + f.substring(6, 8), d = (new Date)
			.Format("yyyy/MM/dd");
	return e = (Date.parse(g) - Date.parse(d)) / 864e5, -45 >= e
			? (alert("您的证书已过期 " + -e + " 天，超过了最后使用期限,请尽快更新!"), !1)
			: e >= 0 && 60 >= e
					? (alert("您的证书还有" + e + "天过期，请尽快更新!"), !0)
					: (0 > e && alert("您的证书已过期 " + -e + " 天，请尽快更新!"), !0)
}
function Login(strFormName, strContainerName, strPin) {
	var ret, objForm = eval(strFormName);
	if (null == objForm)
		return alert("Form Error"), !1;
	if (null == strPin || "" == strPin)
		return alert("请输入Key的保护口令"), !1;
	if (strPin.length < 6 || strPin.length > 16)
		return alert("密码长度应该在6-16位之间"), !1;
	if (!XTXAPP.SOF_Login(strContainerName, strPin)) {
		var retryCount = XTXAPP.SOF_GetPinRetryCount(strContainerName);
		return retryCount > 0
				? (alert("校验证书密码失败!您还有" + retryCount + "次机会重试!"), !1)
				: 0 == retryCount
						? (alert("您的证书密码已被锁死,请联系BJCA进行解锁!"), !1)
						: (alert("登录失败!"), !1)
	}
	var userCert = GetSignCert(strContainerName);
	if (null == userCert || "" == userCert)
		return alert("导出用户证书失败!"), !1;
	if (!CheckValid(userCert))
		return !1;
	if (!VerifySignedData(strServerCert, strServerRan, strServerSignedData))
		return alert("验证服务器端信息失败!"), !1;
	var strClientSignedData = SignedData(strContainerName, strServerRan);
	if (null == strClientSignedData || "" == strClientSignedData)
		return alert("客户端签名失败!"), !1;
	var strSignItem = '<input type="hidden" name="UserSignedData" value="">';
	null == objForm.UserSignedData
			&& objForm.insertAdjacentHTML("BeforeEnd", strSignItem);
	var strCertItem = '<input type="hidden" name="UserCert" value="">';
	null == objForm.UserCert
			&& objForm.insertAdjacentHTML("BeforeEnd", strCertItem);
	var strContainerItem = '<input type="hidden" name="ContainerName" value="">';
	return null == objForm.ContainerName
			&& objForm.insertAdjacentHTML("BeforeEnd", strContainerItem), objForm.UserSignedData.value = strClientSignedData, objForm.UserCert.value = userCert, objForm.ContainerName.value = strContainerName, !0
}
HebcaClient.prototype = {
	_GetClientCtrl : function() {
		if (this.clientCtrl)
			return this.clientCtrl;
		var a;
		try {
			a = new HebcaP11XObject("HebcaP11X.CertMgr")
		} catch (b) {
		}
		return a.Licence = "amViY55oZWKcZmhlnWxhaGViY2GXGmJjYWhlYnGH1QQ5GcNqnW6z3vohVnE+nTJr", this.clientCtrl = a, this.clientCtrl
	},
	LastError : function(a) {
		return HebcaP11XLastError(this._GetClientCtrl(), a)
	},
	Sign : function(a) {
		var b = this._GetClientCtrl().SelectSignCert();
		return b.SignText(a, 1)
	},
	login : function(a) {
		var b = this._GetClientCtrl().SelectSignCert();
		b.Logined ? (b.Logout(), b.Login(a)) : b.Login(a)
	},
	VerifySign : function(a, b, c, d) {
		var e = this._GetClientCtrl().SelectSignCert();
		1 == d ? e.VerifySignatureText(a, b, c) : e
				.VerifySignatureFile(a, b, c)
	},
	GetSignCert : function() {
		return this._GetClientCtrl().SelectSignCert().GetCertB64()
	},
	GetSignCertObj : function() {
		return this._GetClientCtrl().SelectSignCert()
	},
	GetCryptCert : function() {
		return this._GetClientCtrl().SelectEncryptCert().GetCertB64()
	},
	GetSerialNumber : function() {
		return "签名证书序列号："
				+ this._GetClientCtrl().SelectSignCert().GetSerialNumber()
				+ "\n加密证书序列号："
				+ this._GetClientCtrl().SelectEncryptCert().GetSerialNumber()
	},
	GetCN : function() {
		return this._GetClientCtrl().SelectSignCert().GetSubjectItem("CN")
	},
	GetG : function() {
		return this._GetClientCtrl().SelectSignCert().GetSubjectItem("G")
	},
	GetValidTime : function() {
		return "有效期从："
				+ new Date(this._GetClientCtrl().SelectSignCert().NotBefore)
						.toLocaleString()
				+ "\n到:"
				+ new Date(this._GetClientCtrl().SelectSignCert().NotAfter)
						.toLocaleString()
	},
	GetSubjectUniqueID : function() {
		return "签名证书："
				+ this._GetClientCtrl().SelectSignCert().Get_SubjectUniqueID()
				+ "\n加密证书："
				+ this._GetClientCtrl().SelectEncryptCert()
						.Get_SubjectUniqueID()
	},
	GetDeviceSN : function() {
		return this._GetClientCtrl().SelectDevice().SN
	},
	GetCertCount : function() {
		return this._GetClientCtrl().SelectDevice().GetCertCount()
	},
	Encrypt : function(a) {
		return this._GetClientCtrl().SelectEncryptCert().EncryptText(a)
	},
	Decrypt : function(a) {
		return this._GetClientCtrl().SelectEncryptCert().DecryptText(a)
	},
	EncryptB64 : function(a) {
		return this._GetClientCtrl().SelectEncryptCert().EncryptB64(a)
	},
	DecryptB64 : function(a) {
		return this._GetClientCtrl().SelectEncryptCert().DecryptB64(a)
	},
	Login : function(a) {
		this._GetClientCtrl().SelectDevice().Login(a)
	},
	AddToCertStore : function() {
		this._GetClientCtrl().SelectEncryptCert().AddToCertStore(), this
				._GetClientCtrl().SelectSignCert().AddToCertStore()
	},
	DeleteFromCertStore : function() {
		this._GetClientCtrl().SelectEncryptCert().DeleteFromCertStore(), this
				._GetClientCtrl().SelectSignCert().DeleteFromCertStore()
	},
	Logout : function() {
		this._GetClientCtrl().SelectDevice().Logout()
	}
};
var GlobalHebcaP11XObj = null, markCertObj = {
	pluginId : "",
	TaxID : "",
	pluginStatus : !1,
	AlgID : 1,
	certSN : "",
	certStartDate : "",
	certEndDate : "",
	companyName : "",
	certTor : "",
	usbKeyStatus : 1,
	isIE : !1,
	init : function() {
		this.getLoadObject(), this.isIE ? this.pluginId = document
				.getElementById("ccitpluginIE") : this.pluginId = document
				.getElementById("ccitplugin"), this.pluginStatus = !0
	},
	getLoadObject : function() {
		var a, b = this, c = {}, d = navigator.userAgent.toLowerCase();
		return (a = d.match(/msie ([\d.]+)/)) ? c.ie = a[1] : (a = d
				.match(/firefox\/([\d.]+)/)) ? c.firefox = a[1] : (a = d
				.match(/chrome\/([\d.]+)/)) ? c.chrome = a[1] : (a = d
				.match(/opera.([\d.]+)/)) ? c.opera = a[1] : (a = d
				.match(/version\/([\d.]+).*safari/)) ? c.safari = a[1] : 0, c.ie
				? (document
						.write('<object classid="CLSID:B123AD3E-B239-3D19-DD66-0598121ACBDE" id="ccitpluginIE"  width="0" height="0">'), document
						.write("</object>"), void(b.isIE = !0))
				: c.firefox ? void alert("不支持火狐浏览器") : c.chrome
						? void(b.isIE = !1)
						: c.opera ? void alert("不支持opera浏览器") : c.safari
								? void alert("不支持苹果safari浏览器")
								: void 0
	},
	GetCertInfoEX : function() {
		var a = this, b = a.pluginId.GetCertInfoEX(a.TaxID);
		if (0 == b.indexOf("#"))
			alert("得到证书信息失败");
		else {
			var c = b.split("&&");
			6 == c.length
					? (a.certSN = c[0], a.certStartDate = c[1], a.certEndDate = c[2], a.TaxID = c[3], a.companyName = c[4], a.certTor = c[5])
					: alert("获取证书信息不全")
		}
	},
	EncryptData : function(a, b) {
		var c = this, d = c.pluginId.EncryptData(a, "", "", c.TaxID, b);
		return d
	},
	EncryptData2 : function(a, b, c) {
		var d = this, e = d.pluginId.EncryptData2(a, "", "", d.TaxID, b, c);
		return e
	},
	GetVersion : function() {
		var a = this, b = a.pluginId.GetVersion();
		return alert("得到版本检测结果：" + b), b
	},
	SetPeerCert : function(a, b) {
		var c = this, d = c.pluginId.SetPeerCert(a, b);
		return alert("设置加密证书 和 签名证书结果" + d), 0 == d.indexOf("#") ? !1 : !0
	},
	CheckUsbKey : function() {
		var a = this, b = a.pluginId.CheckUsbKey("");
		return a.usbKeyStatus = b, b
	},
	UsbKeyLogin : function(a) {
		var b = this, c = b.pluginId.UsbKeyLogin(b.TaxID, a);
		return "OK" == c ? !0 : !1
	},
	GetCertSubject : function() {
		var a = this, b = a.pluginId.GetCertSubject();
		return b
	}
};
markCertObj.init();
var SGD_SM1_ECB = 257, SGD_SM1_CBC = 258, SGD_SSF33_ECB = 513, SGD_SSF33_CBC = 514, SGD_SMS4_ECB = 1025, SGD_SMS4_CBC = 1026, SGD_3DES_ECB = 8193, SGD_3DES_CBC = 8194, SGD_SM3_RSA = 65537, SGD_SHA1_RSA = 65538, SGD_SHA256_RSA = 65540, SGD_SM3_SM2 = 131329, SGD_SM3 = 1, SGD_SHA1 = 2, SGD_SHA256 = 4, KEY_TYPE_RSA1024 = 1, KEY_TYPE_RSA2048 = 2, KEY_TYPE_SM2_256 = 3, DEVICE_TYPE_LABEL = 1, DEVICE_TYPE_FREESPACE = 2, DEVICE_TYPE_SERIALNUM = 3, DEVICE_TYPE_TYPE = 4, DEVICE_TYPE_KEY_TYPE = 115, DEVICE_TYPE_VID_PID = 116, CERT_VERSION = 1, CERT_SERIAL = 2, CERT_SIGN_METHOD = 3, CERT_ISSUER_C = 4, CERT_ISSUER_O = 5, CERT_ISSUER_OU = 6, CERT_ISSUER_ST = 7, CERT_ISSUER_CN = 8, CERT_ISSUER_L = 9, CERT_ISSUER_E = 10, CERT_NOT_BEFORE = 11, CERT_NOT_AFTER = 12, CERT_SUBJECT_C = 13, CERT_SUBJECT_O = 14, CERT_SUBJECT_OU = 15, CERT_SUBJECT_ST = 16, CERT_SUBJECT_CN = 17, CERT_SUBJECT_L = 18, CERT_SUBJECT_E = 19, CERT_PUBKEY = 20, CERT_SUBJECT_DN = 33, CERT_ISSUER_DN = 34, CERT_UNIQUEID = 35;
try {
	window.ActiveXObject
			? (document
					.writeln('<OBJECT classid="CLSID:3F367B74-92D9-4C5E-AB93-234F8A91D5E6" height=1 id=XTXAPP  style="HEIGHT: 1px; LEFT: 10px; TOP: 28px; WIDTH: 1px" width=1 VIEWASTEXT>'), document
					.writeln("</OBJECT>"))
			: (document
					.writeln("<embed id=XTXAPP0 type=application/x-xtx-axhost clsid={3F367B74-92D9-4C5E-AB93-234F8A91D5E6} event_OnUsbkeyChange=OnUsbKeyChange width=1 height=1 />"), XTXAPP = document
					.getElementById("XTXAPP0"))
} catch (e) {
	alert("ActiveXObject XTXAppCOM.dll可能没有注册成功！" + e.message)
}
var signAlgid = "SHA1withRSA", dwFlags = "0x400000", dwFlags16 = "0x100000", OS = window.navigator.platform;
document
		.write('<object id=pkiAtvNew classid=CLSID:0DC9CA0C-ED42-4C87-A335-1B0BD043FC70 height=0 style="HEIGHT: 0px; LEFT: 0px; TOP: 0px; WIDTH: 0px" width=0>'), document
		.write("</object>");
var HebZjCaObj = {
	getBrowser : function() {
		return isIE ? !0 : !1
	},
	openDevice : function(a) {
		var b;
		pkiAtvNew.OpenDevice("", "", 1, a);
		return b.state = !0, 0 != pkiAtvNew.ErrCode
				? (b.state = !1, b.msg = "打开CA设备失败：[" + pkiAtvNew.ErrCode + "]"
						+ pkiAtvNew.ErrMsg, b)
				: b
	},
	getCertInfo_Nsrsbh : function() {
		var a = this.readCert(2);
		if (0 != a)
			return alert(pkiAtvNew.ErrCode), !1;
		var b = pkiAtvNew.strResult;
		return a = this.getCertInfo(b), 0 != a
				? (alert(pkiAtvNew.ErrCode), !1)
				: pkiAtvNew.strResult
	},
	EncryptData : function(a) {
		var b = this.signInData(a), c = BASE64.encoder(a);
		return b ? c + "@@@@@" + b : !1
	},
	signInData : function(a) {
		return ABCDEF12345678
	},
	readCert : function(a) {
		return pkiAtvNew.readCert(a)
	},
	getCertInfo : function(a) {
		var b = 71;
		return pkiAtvNew.getCertInfo(a, b)
	}
};